import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  

  // 基础
  {
    path: '/basic',
    component: Layout,
    redirect: 'noRedirect',
    name: '基础',
    meta: { title: '基础', icon: 'el-icon-s-operation' },
    children: [
      {
        path: 'Vehicles',
        name: '车辆管理',
        component: () => import('@/views/basic/Vehicles'),
        meta: { title: '车辆管理' }
      },
      {
        path: 'cargoowner',
        name: '货主管理',
        component: () => import('@/views/basic/cargoowner'),
        meta: { title: '货主管理' }
      },
      {
        path: 'Outsourcingunit',
        name: '外协单位管理',
        component: () => import('@/views/basic/Outsourcingunit'),
        meta: { title: '外协单位管理' }
      },
      {
        path: 'Oilcost',
        name: '油费管理',
        component: () => import('@/views/basic/Oilcost'),
        meta: { title: '油费管理' }
      },
      {
        path: 'line',
        name: '线路管理',
        component: () => import('@/views/basic/line'),
        meta: { title: '线路管理' }
      }
    ]
  },

  // 人事
  {
    path: '/kanban',
    component: Layout,
    redirect: 'noRedirect',
    name: '人事',
    meta: { title: '人事', icon: 'el-icon-user' },
    children: [
      {
        path: '/kanban',
        name: '人事看板',
        component: () => import('@/views/personnelmatters/kanban'),
        meta: { title: '人事看板' }
      },
      {
        path: 'registration',
        name: '员工登记',
        component: () => import('@/views/personnelmatters/registration'),
        meta: { title: '员工登记' }
      },
      {
        path: 'Induction',
        name: '入职办理',
        component: () => import('@/views/personnelmatters/Induction'),
        meta: { title: '入职办理' }
      },
      {
        path: 'Departure',
        name: '离职办理',
        component: () => import('@/views/personnelmatters/Departure'),
        meta: { title: '离职办理' }
      },
      {
        path: 'Positive',
        name: '转正办理',
        component: () => import('@/views/personnelmatters/Positive'),
        meta: { title: '转正办理' }
      }
    ]
  },

  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: '合同',
    meta: { title: '合同', icon: 'el-icon-tickets' },
    children: [
      {
        path: 'table',
        name: '货主合同管理',
        component: () => import('@/views/table/index'),
        meta: { title: '货主合同管理' }
      },
      {
        path: 'tree',
        name: '承运合同管理',
        component: () => import('@/views/tree/index'),
        meta: { title: '承运合同管理' }
      },
      {
        path: 'cont',
        name: '通用合同管理',
        component: () => import('@/views/cont/index'),
        meta: { title: '通用合同管理' }
      }
    ]
  },
  // 结算
  {
    path: '/settlement',
    component: Layout,
    redirect: 'noRedirect',
    name: '结算',
    meta: { title: '结算', icon: 'el-icon-s-home' },
    children: [
      {
        path: '/pay',
        name: '应付费管理',
        component: () => import('@/views/settlement/pay'),
        meta: { title: '应付费管理' }
      },
      {
        path: 'charge',
        name: '应收费管理',
        component: () => import('@/views/settlement/charge'),
        meta: { title: '应收费管理' }
      },
      {
        path: 'input',
        name: '进项发票管理',
        component: () => import('@/views/settlement/input'),
        meta: { title: '进项发票管理' }
      },
      {
        path: 'output',
        name: '销项发票管理',
        component: () => import('@/views/settlement/output'),
        meta: { title: '销项发票管理' }
      },
      {
        path: 'payment',
        name: '付款管理',
        component: () => import('@/views/settlement/payment'),
        meta: { title: '付款管理' }
      }
    ]
  },
  // 物资
  {
    path: '/form',
    component: Layout,
    redirect: 'noRedirect',
    name: '物资',
    meta: { title: '物资', icon: 'el-icon-box' },
    children: [
      {
        path: '/index',
        name: '物资管理',
        component: () => import('@/views/form/index'),
        meta: { title: '物资管理' }
      },
      {
        path: '/Storage',
        name: '入库管理',
        component: () => import('@/views/form/Storage'),
        meta: { title: '入库管理' }
      },
      {
        path: '/Consuming',
        name: '物资领用',
        component: () => import('@/views/form/Consuming'),
        meta: { title: '物资领用' }
      },
      {
        path: '/Statistics',
        name: '物资统计',
        component: () => import('@/views/form/Statistics'),
        meta: { title: '物资统计' }
      }
    ]
  },
  // 维护

  {
    path: '/maintain',
    component: Layout,
    redirect: 'noRedirect',
    name: '维护',
    meta: { title: '维护', icon: 'el-icon-box' },
    children: [
      {
        path: '/repair',
        name: '维修记录',
        component: () => import('@/views/maintain/repair'),
        meta: { title: '维修记录' }
      },
      {
        path: '/Maintenancerecord',
        name: '保养记录',
        component: () => import('@/views/maintain/Maintenancerecord'),
        meta: { title: '保养记录' }
      },
      {
        path: '/Violation',
        name: '违章记录',
        component: () => import('@/views/maintain/Violation'),
        meta: { title: '违章记录' }
      },
      {
        path: '/accident',
        name: '事故记录',
        component: () => import('@/views/maintain/accident'),
        meta: { title: '事故记录' }
      },
      {
        path: '/TyreUse',
        name: '轮胎使用记录',
        component: () => import('@/views/maintain/TyreUse'),
        meta: { title: '轮胎使用记录' }
      },
      {
        path: '/Expenserecord',
        name: '费用记录',
        component: () => import('@/views/maintain/Expenserecord'),
        meta: { title: '费用记录' }
      }
    ]
  },

  // 跟踪
  {
    path: '/track',
    component: Layout,
    redirect: 'noRedirect',
    name: '跟踪',
    meta: { title: '跟踪', icon: 'el-icon-s-operation' },
    children: [
      {
        path: 'Cargoownertrack',
        name: '货主合同跟踪',
        component: () => import('@/views/track/Cargoownertrack'),
        meta: { title: '货主合同跟踪' }
      },
      {
        path: 'Carry',
        name: '承运合同跟踪',
        component: () => import('@/views/track/Carry'),
        meta: { title: '承运合同跟踪' }
      },
      {
        path: '/baidua',
        component: () => import('@/views/baidua'),
        hidden: true
      },
    ]
  },

  // 审批
  {
    path: '/Approval',
    component: Layout,
    redirect: 'noRedirect',
    name: '审批',
    meta: { title: '审批', icon: 'el-icon-box' },
    children: [
      {
        path: '/conts',
        name: '货主合同审批',
        component: () => import('@/views/Approval/Conts'),
        meta: { title: '货主合同审批' }
      },
      {
        path: '/index',
        name: '承运合同审批',
        component: () => import('@/views/Approval/index'),
        meta: { title: '承运合同审批' }
      }
    ]
  },

  // 设置
  {
    path: '/setup',
    component: Layout,
    redirect: 'noRedirect',
    name: '设置',
    meta: { title: '设置', icon: 'el-icon-s-tools' },
    children: [
      {
        path: '/basicinformation',
        name: '基础信息设置',
        component: () => import('@/views/setup/basicinformation'),
        meta: { title: '基础信息设置' }
      },
      {
        path: 'operator',
        name: '操作员管理',
        component: () => import('@/views/setup/operator'),
        meta: { title: '操作员管理' }
      },
      {
        path: 'role',
        name: '角色管理',
        component: () => import('@/views/setup/role'),
        meta: { title: '角色管理' }
      },
      {
        path: 'department',
        name: '部门管理',
        component: () => import('@/views/setup/department'),
        meta: { title: '部门管理' }
      },
      {
        path: 'position',
        name: '职位管理',
        component: () => import('@/views/setup/position'),
        meta: { title: '职位管理' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
